package example.db;

import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MariaDBExampleTest {

    @Test
    public void testMariaDBConnection() {
        //jdbc:mariadb:local://<database_file_path>?<connection_parameters>
        //jdbc:mariadb:local://C:/mydatabase.yyds.db?user=myusername&password=mypassword&connectTimeout=10000
        String url = "jdbc:mariadb:local:C:/Users/yangyang/Desktop/TEMP/mydatabase.yyds.db";
        String user = "username";
        String password = "password";

        try (Connection conn = DriverManager.getConnection(url, user, password);
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery("SELECT * FROM mytable")) {

            while (rs.next()) {
                int id = rs.getInt("id");
                String name = rs.getString("name");
                System.out.println("id = " + id + ", name = " + name);
            }
        } catch (SQLException e) {
            throw new RuntimeException("Failed to execute query", e);
        }
    }
}
